Writing code is like painting.
There are techniques to learn, like color-mixing, brush strokes, layering, shading, perspective, etc.
There is also creative intuition: the ability to exercise the techniques you know to create something beautify.
To build beautiful code, you'll need to know the techniques, and you'll need to develop creative intuition.
Over the next few days, we'll talk about important techniques and practice, practice, practice!
def
¶You can define more than one function in a script.
three_reds.py
¶snapshot
¶Bit has the ability to take a snapshot of the world using the snapshot
function.
snap_three_reds.py
¶You can use any phrase you want when making a snapshot.
The Jump
buttons take you to the previous or next snapshot.
cosmo.py
¶When naming a function or variable:
_
(next to the zero key + shift) to break up compound namesgo_green
instead of gogreen
or goGreen
go
instead of Go
or GO
go
is different from Go
!In blue_squares.py
, when will Bit paint a blue square?
blue_squares.py
¶Defining a function is not the same as calling a function.
The very first line after def
can have a string. When this is the case, we call that string a docstring because it documents the function: you use it to describe what the function is for and how to use it.
Strings that use single quotation characters (e.g. "
or '
) are only one line.
If you want to use multiple lines for your string, use triple quotes ("""
or '''
).
Given the following starting world:
Draw four blue smiles:
smiles.py
¶def